package com.hejjon.graph.service.impl;

import com.alibaba.fastjson.JSON;
import com.hejjon.graph.bean.options.Options;
import com.hejjon.graph.request.OptionsConfigRequest;
import com.hejjon.graph.service.OptionsService;
import org.springframework.boot.system.ApplicationHome;
import org.springframework.stereotype.Service;

import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;

/**
 * @author: cs
 * @date: 2025-04-28 07:39:08
 * @since: 1.0
 */
@Service
public class OptionsServiceImpl implements OptionsService {

    @Override
    public Options buildOptions(OptionsConfigRequest request) {

        return takeDefaultOptions();
    }

    private Options takeDefaultOptions() {
        Options options = new Options();
        ApplicationHome home = new ApplicationHome(OptionsServiceImpl.class);
        String path = home.getSource().getPath();
        String fileFullName = path + "\\config\\default-options.json";
        try {
            String content = new String(Files.readAllBytes(Paths.get(fileFullName)), StandardCharsets.UTF_8);
            options = JSON.parseObject(content, Options.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return options;
    }




}
